import axios from 'axios'
import { Toast } from 'vant';

const http = axios.create({
	baseURL:'https://m.maizuo.com',
	Timeout:10000,
	headers:{
		'X-Client-Info':'{"a":"3000","ch":"1002","v":"5.2.0","e":"16416303021669629881614337","bc":"110100"}'
	}
})

//axios拦截器
//再发请求之前拦截
http.interceptors.request.use(function (config) {
    // Do something before request is sent
	Toast.loading({
	  message: '加载中...',
	  forbidClick: true,
	});
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// 在成功之后拦截
http.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
	Toast.success('yeah!加载成功！')
	Toast.clear();
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
	Toast.fail('Oh!加载失败！');
	Toast.clear();
    return Promise.reject(error);
  });

export default http